/*
 * TimeoutTimer.cpp
 *
 *  Created on: 2009-8-20
 *      Author: fanliangliang
 */

#include "TimeoutTimer.h"
#include "TimeoutListener.h"
#include "Common.h"

CTimeoutTimer* CTimeoutTimer::NewL(MTimeoutListener& aListener, TPriority aPriority /*= EPriorityStandard*/) {
	CTimeoutTimer* self = NewLC(aListener, aPriority);
	CleanupStack::Pop(self);
	return self;
}

CTimeoutTimer* CTimeoutTimer::NewLC(MTimeoutListener& aListener, TPriority aPriority /*= EPriorityStandard*/) {
	CTimeoutTimer* self = new (ELeave) CTimeoutTimer(aListener, aPriority);
	CleanupStack::PushL(self);
	self->ConstructL();
	return self;
}

CTimeoutTimer::CTimeoutTimer(MTimeoutListener& aListener, TPriority aPriority)
:CTimer(aPriority)
,iListener(aListener) {
	
}

CTimeoutTimer::~CTimeoutTimer() {
	Cancel();
}

void CTimeoutTimer::ConstructL() {
	CTimer::ConstructL();
	CActiveScheduler::Add(this);
}

void CTimeoutTimer::RunL() {
    // Timer request has completed, so notify the timer's owner
	if (iStatus == KErrNone) {
		iListener.OnTimerExpired();
	}
	else {
		User::LeaveIfError(iStatus.Int());
	}
}

void CTimeoutTimer::After(TTimeIntervalSeconds anInterval) {
	CTimer::After(anInterval.Int() * KMicroSecondsPerSecond);
}
